<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax_users extends CI_Controller {
    
    function Ajax_users()
    {
        parent::__construct();
    }
    
    function login()
    {
        $this->load->model('user_model');
        
        $fields = array('username', 'password');
        
        $error = 0;
        foreach($fields as $field)
        {
            if(! $this->input->post($field))
            {
                $error = 1;
            }
        }
        
        $account = array(
            'username' => $this->input->post('username'),
            'password' => md5($this->input->post('password'))
        );
        
        $result = $this->user_model->login($account);
        if(! $result)
        {
            $error = 1;
        }
        else
        {
            $this->session->set_userdata(array('user_id' => $result));
        }
        
        $data['error'] = $error;
        
        echo json_encode($data);
    }
    
}

/* End of file ajax_users.php */
/* Location: ./application/controllers/ajax_users.php */